package com.gupaoedu.baifc.staticproxy;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * projectName: baifc_proxy
 * packageName: com.gupaoedu.baifc.staticproxy
 * Created: 2019/3/18.
 * Auther: baifc
 * Description:
 */
public class OrderServiceProxy implements IOrderService {

    private IOrderService orderService;

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy");

    public OrderServiceProxy(IOrderService orderService) {
        this.orderService = orderService;
    }


    public void createOrder(Order order) {
        // 获取年份
        Date createTime = order.getCreateTime();
        int year = Integer.parseInt(sdf.format(createTime));

        DynamicDataSourceEntry.set(year);
        System.out.println("数据源已切换到【DB_" + year + "】");

        orderService.createOrder(order);

    }
}
